<script language="javascript">    
    //Number
    (function($){        
        $(document).ready(function() {
            $("#search_new").submit(function(e) {                
                var invalid_number = false;                
                var element_val = $("#maxprice_new").val();
                if(element_val != '') {            
                    var reg_number = /^[0-9]*$/;
                    if(!reg_number.test(element_val))
                        invalid_number = true;

                    var next_element = $("#maxprice_new").parent();
                    $(next_element).find('div.error').remove();
                }

                if(invalid_number) {
                    $("#maxprice_new").css('border-color', 'red');
                    $(next_element).append('<div class="error">Invalid number</div>');                        
                }
                else 
                    $(this).css('border', '1px solid #DADADA');

                if(invalid_number)
                    e.preventDefault();
            }); 
        });
    })(jQuery);
</script>
<?php 
    echo form_open(base_url()."index.php/car/result", array ('id'=>'search_new')); 
?>
    <input type="hidden" name="cartype" value="new" />
    <h1 class="blue">Find New Cars</h1>
    <p>Make</p>
    <p>
        <select name="make" id="make">
            <option value="">All Make</option>
<?php 
            foreach($make->result() as $row)
            { 
?>
            <option value="<?php echo $row->id; ?>"><?php echo $row->name; ?></option>
<?php
            }
?>        
        </select>
    </p>
    <p>Model</p>
    <p>
        <select name="model" id="model">
            <option value="">All Model</option>
        </select>
    </p>
    <p>Maximum Price</p>
    <p>
        <input type="text" name="maxprice" class="number" id="maxprice_new" />
    </p>
    <p>Dealer</p>
    <p>
        <select name="dealer" style="width: 260px;">
            <option value="">Please select</option>
<?php 
            foreach($dealer->result() as $row)
            { 
?>
                <option><?php echo $row->company; ?></option>
<?php
            }
?>    
        </select>
    </p>
    <p>Year</p>
    <p>
        <select name="year">
            <option value="">Please select</option>
<?php 
            date_default_timezone_set("GMT");
            $current_year = date("Y");

            for($counter = $current_year + 1; $counter >= $current_year - 1; $counter--)
            { 
?>
            <option>
<?php 
                echo $counter;
?>
            </option>
<?php
            }
?>    
        </select>
    </p>
    <p>Location</p>
    <p>
        <select name="location">
            <option value="">Please select</option>
<?php 
            foreach($location->result() as $row)
            { 
?>
            <option>
<?php 
                echo $row->province; 
?>
            </option>
<?php
            }
?>    
        </select>
    </p>           
<?php 
    echo form_submit(array ('name'=>'search', 'class'=>'btnsearch'), '');
    echo form_close();
?>